## -*- coding: utf-8 -*-
<%inherit file="/derived/blog/blog_base.html"/>
<%!
    from pythonblog.service.section_service import get_section
%>
<div id="main">
    <h3>创建新文章</h3>
    ${h.form(h.url_for(controller='post', action='save', sub_domain=c.userInfo.userName), method='post', id='blog_form')}
    <table width="100%">
        <tbody>
            <tr><td>${h.hidden('id')} ${h.hidden('abstract')}</td><td></td></tr>
            <tr>
                <td class="row1">主题</td>
                <td> ${h.text('title', class_='text', style='width: 400px;')}</td>
            </tr>
            <tr>
                <td class="row1">文章分类</td>
                <td>${h.select("type", 1, [[1, u"原创"], [2, u"转载"], [3, u"新闻"], [4, u"翻译"]])}
                    <%!
                    from pythonblog.service.section_service import all_sections
                    %>
                    ${h.select("section_id", 1, ((section.id, section.name) for section in all_sections.values()))}
                </td>
            </tr>
            <tr>
                <td class="row1">文章标签<span style="color: red; margin-left: 5px; font-weight: normal;">(用逗号隔开) </span> </td>
                <td>${h.text('tags', class_='text', style='width: 250px;')}</td>
            </tr>
            <tr>
                <td class="row1">正文 </td>
                <td></td>
            </tr>
            <tr>
                <td colspan="2" style="border-top: 1px solid rgb(204, 204, 204);"> </td>
            </tr>
            <tr><td></td><td></td></tr>
            <tr>
                <td id="editWrapper" style="" colspan="2">${h.textarea('content', '', style='width:680px;height:400px;')}</td>
            </tr>
            <tr>
                <td style="padding-top: 10px;" colspan="2"> 提示：内容长度最大64KB，约2万多汉字，如果出现超长（比如从Word粘贴带格式文本）被截断的问题，请分开发布 </td>
            </tr>
            <tr>
                <td style="padding: 15px 0px 25px;" colspan="2">
                    <input id="btnSubmit" class="submit" type="button" value="发布" />
                    %if not c.is_posted:
                    <input id="btnSaveDraft" class="submit" type="button" value="存为草稿" />
                    %else:
                    ${h.hidden('is_posted', value=c.is_posted)}
                    %endif
                </td>
            </tr>
        </tbody>
    </table>
    ${h.end_form()}
</div>

<%def name="head()">
${parent.head()}
${h.javascript_link(h.url_for('/js/nicEdit.js'))}

<script type="text/javascript">
    var contentTextArea;
    $(document).ready(function() {

        $('#btnSubmit').click(function(e) {
            setValues(contentTextArea);
            if (validateTitle() && validateContent()) {
                $("#btnSubmit, #btnSaveDraft").attr('disabled', 'true');
                $("#blog_form").submit();
            }
        });

        $('#btnSaveDraft').click(function(e) {
            setValues(contentTextArea);
            if (validateTitle()) {
                $("#btnSubmit, #btnSaveDraft").attr('disabled', 'true');
                $("#blog_form").attr("action","${h.url_for(controller='post', action='save_draft', sub_domain=c.userInfo.userName)}");
                $("#blog_form").submit();
            }
        });

        contentTextArea = new nicEditor({maxHeight : 400,
            iconsPath : "${h.url_for('/js/nicEditorIcons.gif')}",
            buttonList : ['bold','italic','underline','left','center','right','ol','ul','fontSize','indent','outdent','image','link','unlink','forecolor']
        }).panelInstance('content');

    });

</script>
</%def>